/*
 * Middleware
 * Copyright (C) 2010/11
 * Riccardo Pulvirenti, Giuseppe Ravidà, Andrea Tino
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANDABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see http://www.gnu.org/licenses
 */

/*!
 * File: tqueue_manager.hpp
 */

#ifndef _TQUEUE_MANAGER_HPP_
#define _TQUEUE_MANAGER_HPP_

#include <iostream>
#include <string>

#include "task_descriptor.hpp"
#include "tqueue.hpp"
#include "synqueue.cpp"

using namespace middleware::queueing;

//-----------------------------------------------------------------------------
// Enum, struct, aliases

//-----------------------------------------------------------------------------
// Constants
namespace middleware {
/*!
 * Defines the upper limit of the queue.
 */
const unsigned int kMaxTasksInQueue = 25;
}
//-----------------------------------------------------------------------------
// Class definitions
namespace middleware {
/*!
 * Manages the queue of task descriptors between Manager and Worker.
 * It resides in worker.
 */
class TQueueManager : public TQueue {
public:
	typedef SynQueue<TaskDescriptor, kMaxTasksInQueue>::Reference
			TaskReference; /* Reference to a task descriptor */
	typedef const SynQueue<TaskDescriptor, kMaxTasksInQueue>::ConstReference
			TaskConstReference; /* Const reference to a task descriptor */
	/*!
	 * Constructs a new TQueueManager with an empty queue of task descriptors.
	 */
	TQueueManager();
	/*!
	 * Destructor.
	 */
	~TQueueManager();
	/*!
	 * Enqueues a task.
	 */
	void enqueue(TaskConstReference task);
	/*!
	 * Dequeues a task.
	 */
	TaskDescriptor dequeue();
	/*!
	 * Gets the queue size.
	 */
	unsigned int size();
private:
	/*!
	 * Synchronized queue of tasks. Limit = kMaxTasksInQueue.
	 */
	SynQueue<TaskDescriptor, kMaxTasksInQueue> _tasks_queue;
}; /* WFQueueManager */
} /* middleware */

#endif
